Differences Between Rural and Urban School Districts (1 of 3)
Below are the datasets I plan to use for my story.
https://data-msdis.opendata.arcgis.com/datasets/mo-public-school-districts/explore
https://data-msdis.opendata.arcgis.com/datasets/mo-2020-public-schools/explore
We always hear about the urban rural divide so I wanted to highlight differences between more populated counties and more rural counties. More speciifically looking at rural vs urban school districts.
I'd like to examine student/teacher ratios and school density by land area.
My target audience is Missouri residents who are interested in education and differences between rural and urban areas. My hope with this project is to provide insights into the differences rural and urban counties experience pertaining to educational facilities and resources. People viewing this story will have a better understanding of possible challenges districts face regarding class size and district transportation.
from pathlib import Path
import urllib.request
import shutil
import geopandas as gpd
import pandas as pd
import json
import folium
from folium.plugins import MarkerCluster
from branca.colormap import linear
pd.set_option('display.max_columns', None)
file_url = 'https://services2.arcgis.com/kNS2ppBA4rwAQQZy/ArcGIS/rest/services/MO_Public_School_Districts/FeatureServer/0?f=pjson'
local_file_name = 'MO_Public_School_Districts.json'
file_path = Path('../exercises/')
file_path /= local_file_name
with urllib.request.urlopen(file_url) as response, file_path.open(mode = 'w+b') as out_file:
shutil.copyfileobj(response, out_file)
mo_districts = gpd.read_file('MO_Public_School_Districts.shp', layer = 0)
mo_schools = gpd.read_file('MO_2020_Public_Schools.shp', layer = 0)
mo_districts.head()
mo_schools.head()
mo_schools.describe()
mo_districts.describe()
totalTeachers = mo_schools.groupby('CtyDist')['Teachers'].sum().to_frame().reset_index()
totalTeachers.columns = ['DIST_CODE', 'Teachers']
totalTeachers.head()
totalStudents = mo_schools.groupby('CtyDist')['Enrollment'].sum().to_frame().reset_index()
totalStudents.columns = ['DIST_CODE', 'Students']
totalStudents.head()
SchoolsPerDist = mo_schools.groupby('CtyDist').size().to_frame().reset_index()
print(SchoolsPerDist.shape)
SchoolsPerDist.head()
SchoolsPerDist.columns = ['DIST_CODE', 'SchoolsPerDist']
SchoolsPerDist.head()
print(SchoolsPerDist.shape)
SchoolsPerDist.dtypes
print(mo_districts.shape)
mo_districts.dtypes
districts = pd.merge(mo_districts, SchoolsPerDist, how='left')
districts = pd.merge(districts, totalTeachers, how='left')
districts = pd.merge(districts, totalStudents, how='left')
districts.head()
districts['StudentsPerTeacherDistrictAVG'] = districts.Students/districts.Teachers
districts['SqMilesPerSchool'] = districts.Area_SqMil/districts.SchoolsPerDist
districts.sort_values('SqMilesPerSchool', ascending = False).head()
districtsMap = folium.Map([38.318364, -92.412253], tiles='CartoDB Positron', zoom_start=6.5)
# generate choropleth map
choropleth = folium.Choropleth(
geo_data=districts,
data=districts,
columns=['NAME', 'SchoolsPerDist'],
key_on='feature.properties.NAME',
fill_color='Reds',
fill_opacity=1,
line_opacity=1,
legend_name='Schools per Schools District',
highlight=True,
smooth_factor=0).add_to(districtsMap)
style_function = "font-size: 15px; font-weight: bold"
choropleth.geojson.add_child(
folium.features.GeoJsonTooltip(['NAME','SchoolsPerDist'], style=style_function, labels=False))
# create a layer control
folium.LayerControl().add_to(districtsMap)
districtsMap